package cn.org.eshow.webapp.action;

import cn.org.eshow.bean.query.MoneyQuery;
import cn.org.eshow.model.Money;
import cn.org.eshow.model.User;
import cn.org.eshow.service.MoneyManager;
import cn.org.eshow.util.JacksonUtil;
import cn.org.eshow.webapp.util.RenderUtil;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * 碳贝API接口
 */
@AllowedMethods({"mine"})
public class MoneyAction extends ApiBaseAction<Money> {

    private static final long serialVersionUID = 1L;

    @Autowired
    private MoneyManager moneyManager;

    private Money money = new Money();
    private List<Money> moneys = new ArrayList<Money>();
    private MoneyQuery query = new MoneyQuery(Boolean.TRUE);

    /**
     * 获取我的用户账户信息
     */
    public void mine() {
        User user = accessTokenManager.isValid(accessToken);
        if (user == null) {
            RenderUtil.expires();//用户信息过期
            return;
        }
        query.setUserId(user.getId());
        Money old = moneyManager.mine(user);
        RenderUtil.success("获取成功", "money", JacksonUtil.toJson(old));
    }

    public Money getMoney() {
        return money;
    }

    public void setMoney(Money money) {
        this.money = money;
    }

    public List<Money> getMoneys() {
        return moneys;
    }

    public void setMoneys(List<Money> moneys) {
        this.moneys = moneys;
    }

    public MoneyQuery getQuery() {
        return query;
    }

    public void setQuery(MoneyQuery query) {
        this.query = query;
    }

}